package day18.tarena.Thred;

public class TestSleep extends Thread{
	
	public void run() {
		for (int i = 0; i <1000; i++) {
			System.out.println(Thread.currentThread().getName()+":" + i);
			try {
			//	Thread.sleep(1);
				Thread.yield();   //yield 退出，让位 
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		TestSleep ts1 = new TestSleep();                  
		ts1.setPriority(2);
		ts1.start();
		TestSleep ts2 = new TestSleep();  //刚好让位的时候，优先级高的时间片用完了，就只有轮到优先级底的来运行。
		ts2.setPriority(2);
		ts2.start();
	}
}
